<?php

include_once dirname(dirname(__FILE__)) . '/dal/journal_dal.php';
include_once dirname(dirname(__FILE__)) . '/dal/paper_dal.php';

function loadJournal($journal_id) {
    return getJournal($journal_id);
}

function loadAllCategoriesByJournalID($journal_id) {
    return getAllCategoriesByJournalID($journal_id);
}

function loadAllJournalSubDetByCatID($category_id) {
    return getAllJournalSubDetByCatID($category_id);
}

function loadCategory($category_id) {
    return getCategoryById($category_id);
}

function loadAllJournalSubDetByJournalID($journal_id) {
    return getAllJournalSubDetByJournalID($journal_id);
}

function loadAllPapersByJournalIDnDated($journal_id, $month, $year) {
    return getAllPapersByJournalIDnDated($journal_id, $month, $year);
}

function load_all_archive_by_journal_id($journal_id) {
    $papers = getAllPapersByJournalID($journal_id);
    $archives = array();
    $count = 0;
    foreach ($papers as $i => $item) {
        if (!empty($item["DateByUser"])) {
            $date=date_create($item["DateByUser"]);
            $month = date_format($date, 'm');
            $year = date_format($date, 'Y');
            $date_string = date_format($date, 'F Y');
            $archive = array();
            $archive['month'] = $month;
            $archive['year'] = $year;
            $archive['date_string'] = $date_string;
            $archive['journal_id'] = $item["JournalID"];
            if ($count == 0 || $archive['date_string'] != $archives[$count - 1]['date_string']) {
                $archives[$count] = $archive;
                $count = $count + 1;
            }
        }
    }
    return $archives;
}

function loadPapersById($paper_id) {
    return getPapersById($paper_id);
}